﻿#define CATCH_CONFIG_MAIN 
#include "catch.hpp"
#include "any_list.h"

std::string generateRandomString(size_t length) {
	const std::string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	std::string randomString;
	randomString.reserve(length);

	for (size_t i = 0; i < length; ++i) {
		char randomChar = characters[rand() % characters.size()];
		randomString += randomChar;
	}

	return randomString;
}

TEST_CASE("Arraylist", "[use]") {
	ArrayList list;
	list << 1 << 2.0f << 3.0 << 4 << "5";
	
	list.add_attr(int64_t{ 34 });


	int a = list.get_attr<int>(0);
	float b = list.get_attr<float>(1);
	double c = list.get_attr<double>(2);
	int d = list.get_attr<int>(3);
	const char* e = list.get_attr<const char*>(4);


	auto temp = list.get_attr<int>(0);                                  
	REQUIRE(list.get_attr<int>(0) == 1);
	REQUIRE(list.get_attr<float>(1) == 2.0f);
	REQUIRE(strcmp(list.get_attr<const char*>(4), "5") == 0);

	//Assert::AreEqual(list.set_attr(0, 0.1), false);
	REQUIRE(list.set_attr(0, 2));
	REQUIRE(list.get_attr<int>(0) == 2);

	REQUIRE(list.set_attr(4, "dsfsafsadfasd"));
	REQUIRE(strcmp(list.get_attr<const char*>(4), "dsfsafsadfasd") ==0);
	list.clear();
	for (int i = 0; i < 1000; ++i) {
		REQUIRE(list.add_attr(i));
		REQUIRE(list.get_attr<int>(i) == i);
	}
	list.clear();
	for (int i = 0; i < 1000; ++i) {
		REQUIRE(list.add_attr(i+ 0.01));
		REQUIRE(list.get_attr<double>(i) == i + 0.01);
	}

	list.clear();
	for (int i = 0; i < 1000; ++i) {
		REQUIRE(list.add_attr(i + 0.01f));
		REQUIRE(list.get_attr<float>(i) == i + 0.01f);
	}

	list.clear();
	for (int i = 0; i < 1000; ++i) {
		auto value = generateRandomString(i % 100);
		REQUIRE(list.add_attr(value.c_str()));
		
		REQUIRE(strcmp(value.c_str(), list.get_attr<const char*>(i)) == 0);
	}

}
